import asyncio

import sys

# 如果是 Windows 系统，设置使用 SelectorEventLoop
if sys.platform.startswith('win'):
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

from fastmcp import Client
from fastmcp.client.transports import StdioTransport

transport = StdioTransport(
    command="python",
    args=["server.py"]
)


async def main():
    try:
        async with Client(transport) as client:
            print("Connected to server")
            tools = await client.list_tools()
            print("Available tools:", [t.name for t in tools])
            res = await client.call_tool("print_message", {"message": "Hello, world!"})
            print( res.content[0].text)
    except Exception as e:
        print(e)


if __name__ == "__main__":
    asyncio.run(main())
